<template>
	<view>
		<view class="show-name">{{joinInfo.name}}</view>
		<preview-form ref="preview" :dataList="list" v-if="list.length > 0"></preview-form>
		<view class="button" @tap="submit" v-if="showSubmit == true">立即修改</view>
	</view>
</template>

<script>
	import previewForm from "@/components/diy-form/preview-form.vue";
	
	export default {
		components:{
			previewForm
		},
		data() {
			return {
				showSubmit:false,
				circle_id:0,
				joinInfo:{},
				list:[]
			}
		},
		onLoad(params) {
			//params.circle_id = 10010;
			if(params.circle_id)
			{
				this.circle_id = params.circle_id;
				this.getJoinInfo();
			}
		},
		methods: {
			async submit(){
				var that = this;
				var checkLogin = that.$api.checkLogin(true);
				if(checkLogin == false)
				{
					that.$api.navigateTo('/pages/member/login');return ;
				}
				//this.$refs.preview.uploadFile(); //检测上传文件
				that.$api.showModal('确认修改','',async function(res){
					if(res == 'yes')
					{
						if(that.joinInfo.formlist != '')
						{
							var resData = await that.$refs.preview.getFormData(); //获取最终数据方法
							//console.log('join resData',resData);return ;
							//console.log('join resData',resData);
							if(!resData || resData.length < 1)
							{
								return false;
							}
						}else{
							var resData = '';
						}
						that.$api.loadingMsg('正在修改');
						that.$http.post('circle/joinUserCircleEdit',{
							resData,
							circle_id:that.circle_id,
							type:'edit'
						}).then(res=>{
							that.$api.msg(res.msg)
							if(res.code == 1)
							{
								that.showSubmit = false;
								setTimeout(function(){
									that.$api.navbackTo();
								},2000)
							}
						})
					}
				})
				//var check = this.$refs.preview.checkFormData();  //检测填写数据是否完善
				//console.log(resData)
			},
			getJoinInfo(){
				var that = this;
				that.$http.post('circle/getUserJoinCicleInfo',{
					circle_id:that.circle_id
				}).then(res=>{
					if(res.code == 1)
					{
						var joinInfo = res.data.joinInfo;
						that.joinInfo = joinInfo;
						if(joinInfo.formlist)
						{
							that.list = JSON.parse(joinInfo.formlist)
						}
						if(joinInfo.content)
						{
							setTimeout(function(){
								var contentArr = JSON.parse(joinInfo.content);
								that.$refs.preview.saveInitResultData(contentArr)
							},100)
						}
						that.showSubmit = true;
					}else{
						that.$api.msg(res.msg);
					}
					
				})
			},
		}
	}
</script>

<style lang="scss">
	.show-name{
		background: #FFFFFF;
		width: 94%;
		margin: 20rpx 3%;
		border-radius: 20rpx;
		line-height: 40px;
		height: 80rpx;
		overflow: hidden;
		text-align: center;
		color: #999999;
	}
	.button{
		height: 80rpx;
		width: 90%;
		margin: 50rpx auto;
		background-color:$uni-btn-color;
		color: #ffffff;
		text-align: center;
		line-height: 80rpx;
		letter-spacing: 2rpx;
		border-radius: 30rpx;
	}
</style>
